package com.stockz.equity.indicator.vsa.property;

import java.util.List;

import com.stockz.equity.indicator.vsa.VsaBar;
import com.stockz.equity.model.Bar;

public class Type extends RangeEnum {

	public static final Type Up = new Type("Up",1,Double.MAX_VALUE,101);
	public static final Type Average = new Type("Average",2,100,99);
	public static final Type Down = new Type("Down",3,98,0);
	
	private static final Type[] types = new Type[]{Up,Average,Down};
	
	public static Type[] values(){
		return types;
	}
	
	public static void analyze(List<Bar> barList,int index,VsaBar vsaBar){
		if(barList == null || barList.isEmpty() || 
				 index < 0 || index >= barList.size()-1 || vsaBar == null){
			return;
		}
		
		Bar previous = barList.get(index+1);
		Bar current = barList.get(index);
		
		/*double percentage = current.getAveragePrice()*100/previous.getAveragePrice();
		
		for(Type type : Type.values()){
			if(percentage <= type.getUpperLimit() && percentage >= type.getLowerLimit()){
				vsaBar.setType(type);
				break;
			}
		}*/
		/*if(current.getClose() > previous.getClose()){
			vsaBar.setType(Up);
		}else if(current.getClose() < previous.getClose()){
			vsaBar.setType(Down);
		}else{
			vsaBar.setType(Average);
		}*/
		
		if(current.getAveragePrice() > previous.getAveragePrice()){
			vsaBar.setType(Up);
		}else if(current.getAveragePrice() < previous.getAveragePrice()){
			vsaBar.setType(Down);
		}else{
			vsaBar.setType(Average);
		}
	}
	
	public Type(String name, int ordinal, double upperLimit, double lowerLimit) {
		super(name, ordinal, upperLimit, lowerLimit);
	}

}
